package com.itheima.mapper;

import com.itheima.bean.Classes;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface ClassesMapper {

    @Select("select * from classes")
    @Results({
            @Result(property="id",column="id"),
            @Result(property="name",column="name"),
            @Result(property="students",column="id",
                    javaType=List.class,
                    many=@Many(select="com.itheima.mapper.StudentMapper.findByCid")
            )
    })
    List<Classes> findAll();


    @Select("select * from classes where id=#{id}")
    Classes findById(Integer cid);
}
